package com.module.controller;

import com.module.framework.domain.ResponseResult;
import com.module.framework.domain.Role;
import com.module.framework.service.MenuService;
import com.module.framework.service.RoleService;
import com.module.framework.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author JiHuiQin
 * @Date 2022/3/2 19:47
 * @Version 1.0
 */

@RestController
@RequestMapping("/admin/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Autowired
    private MenuService menuService;

    @GetMapping("/list")
    public ResponseResult RoleList(Integer pageNum, Integer pageSize, String name) {
        PageVO pageVO = roleService.getRoleList(pageNum, pageSize, name);
        return ResponseResult.okResult(pageVO);
    }

    @PostMapping("/add")
    public ResponseResult addRole(@RequestBody Role role) {
        roleService.addRole(role);
        return ResponseResult.okResult();
    }

    @PostMapping("/update")
    public ResponseResult updateRole(@RequestBody Role role) {
        roleService.updateRole(role);
        return ResponseResult.okResult();
    }

    @GetMapping("/delete")
    public ResponseResult deleteRole(Integer id) {
        roleService.deleteRole(id);
        return ResponseResult.okResult();
    }

    @GetMapping("/{roleId}")
    public ResponseResult permission(@PathVariable Integer roleId) {
        return ResponseResult.okResult(menuService.selectPermsByRoleId(roleId));
    }

}
